package myTest;

import index.Indexator;
import index.Indexator_WithPreliminarySorting;
import index.Indexator_WithTempFiles;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;

import net.barashev.seclub.CmdLineOptions;
import net.barashev.seclub.corpus.Corpus;
import net.barashev.seclub.corpus.Document;
import net.barashev.seclub.corpus.MemoryCorpus;
import net.barashev.seclub.corpus.wikipedia.WikipediaFileCorpus;
import net.barashev.seclub.io.BufferManager;
import net.barashev.seclub.io.DataMarshaller;
import net.barashev.seclub.io.IteratingSlot;
import net.barashev.seclub.io.OutputSlot;
import net.barashev.seclub.io.Sorter;
import net.barashev.seclub.io.file.DiskFileManager;
import net.barashev.seclub.io.file.FileManager;
import net.barashev.seclub.io.file.MemoryFileManager;
import net.barashev.seclub.io.file.VFile;
import net.barashev.seclub.io.marshaller.IntegerComparator;
import net.barashev.seclub.io.marshaller.IntegerMarshaller;

public class CreateIndexForWikFile {

    static class MyOptions extends CmdLineOptions {
        @Option(name="-ram_bytes")
        public int ram_bytes = 100000; // 100k
    }
    public static void main(String[] args) throws IOException, CmdLineException {
        System.out.println("START TEST_SE \n");
        MyOptions options = new MyOptions();
        CmdLineParser parser = new CmdLineParser(options);
        parser.parseArgument(args);

        Corpus corpus = getCorpus();

        DiskFileManager fileMgr = new DiskFileManager(options.index_dir);
        System.out.println("Creating index in "
                + fileMgr.getRoot().getAbsolutePath());
        BufferManager bufferMgr = new BufferManager(options.block_size_bytes,
                options.buffer_size_blocks);

        Indexator_WithTempFiles indexator = new Indexator_WithTempFiles(corpus, fileMgr, bufferMgr, options.ram_bytes);
        indexator.index();
        
        System.out.println("\n FINISHED!!!");
		System.out.println("used size memory = " + options.ram_bytes+ " byte");
		System.out.println("timeTmpFiles = " + indexator.timerTempFiles.getDurationInMiliSec()+ " ms");
		long fullTime = indexator.getDurationInMiliSec();
		System.out.println("fullTime = " + fullTime + " ms (" + (fullTime/(60*1000)) + " min)");
    }

    private static Corpus getCorpus() {
        WikipediaFileCorpus corpus = new WikipediaFileCorpus("/net/barashev/seclub/sample/wikipedia.xml");
        return corpus;
    }

}
